# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=staticcheck
pkgver=2023.1.6
pkgrel=1
pkgdesc="The advanced Go linter"
arch=('loong64' 'x86_64')
url="https://staticcheck.io"
license=("MIT")
depends=('glibc')
makedepends=('go' 'git')
options=('!lto')
source=("$pkgname-$pkgver.tar.gz::https://github.com/dominikh/go-tools/archive/$pkgver.tar.gz")
sha512sums=('f6b777f5b36cfbfa41bee4242215e235a6ca8d61b075197018d7e404ab79d886067a4a8f63055e5191f3a57d529ccb15f04801c5999b86708b0cb767711366ba')
b2sums=('0c0251fba269c3e74ebfceeb32b85d1b69ce876ac05389f64a64b2fefce34ac90fd727ac7705a03efb91e3ad0ba04944d30a13277c94f8cac0bca8583a71e282')

prepare(){
	cd "go-tools-$pkgver"
	mkdir -p bin
}

build(){
	cd "go-tools-$pkgver"

  # set Go flags
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export GOPATH="${srcdir}"

  go build -v \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-compressdwarf=false \
    -linkmode external \
    -extldflags ${LDFLAGS}" \
    -o bin\
    ./cmd/staticcheck
}

check(){
	cd "go-tools-$pkgver"
	GOROOT="/usr/lib/go" go test -v ./...
}

package(){
	cd "go-tools-$pkgver"
	install -p -Dm755 bin/staticcheck "${pkgdir}/usr/bin/staticcheck"
	install -Dm644 "LICENSE"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENCE"
	install -Dm644 "LICENSE-THIRD-PARTY"  "${pkgdir}/usr/share/licenses/${pkgname}/LICENCE-THIRD-PARTY"
}
